<template>
  <j-modal
    :title="title"
    :width="600"
    :visible="visible"
    switchFullscreen
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    @ok="handleOk"
  >
    <a-form-model layout="horizontal" ref="realForm" :model="model" :rules="validatorRules" v-bind="formItemLayout">
      <z-form-item :datas="fieldArr" :form="model" :rules="validatorRules" :gutter="0" />
    </a-form-model>
  </j-modal>
</template>

<script>
import Vue from 'vue'
import { USER_INFO } from '@/store/mutation-types'
import { informationDisposal, getDisposalDetails } from '@/api/sjsk/alarmService'
export default {
  props: [],
  data() {
    return {
      title: '处置',
      visible: false,
      disableSubmit: false,
      model: {},
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 16 }
      },
      fieldArr: [
        {label: '模型名称', prop: 'modelName', tagType: 'input', disabled: true},
        {label: '命中时间', prop: 'hitTime', tagType: 'input', disabled: true},
        {label: '情报号码', prop: 'intelligenceNumber', tagType: 'input', disabled: true},
        {label: '处置人员', prop: 'disposalPersonName', tagType: 'input', disabled: true},
        {label: '处置说明', prop: 'disposalInstructions', tagType: 'textarea', disabled: false},
      ],
      validatorRules: {
        disposalInstructions:[ { required: true, message: '请输入处置说明' }]
      }
    }
  },
  created() {},
  methods: {
    show(record, type) {
      this.visible = true
      this.$set( this.model, 'modelName', record.modelName )
      if(type === 'add') {
        this.title = '处置'
        this.disableSubmit = false
        this.fieldArr.forEach(item=> {
          if(item.prop=='disposalInstructions') item.disabled = false
        })
        let userInfo = Vue.ls.get(USER_INFO)
        this.$set( this.model, 'disposalPersonId', userInfo.id )
        this.$set( this.model, 'disposalPersonName', userInfo.realname )
        this.$set( this.model, 'infoId', record.infoId )
        this.$set( this.model, 'hitTime', record.createTime )
        this.$set( this.model, 'intelligenceNumber', record.intelligenceNumber )
      } else if(type === 'details') {
        this.title = '处置结果'
        this.disableSubmit = true
        this.fieldArr.forEach(item=> {
          if(item.prop=='disposalInstructions') item.disabled = true
        })
        this.getDisposalDetails(record.infoId)
      }
    },
    getDisposalDetails(infoId) {
      getDisposalDetails(infoId).then((res) => {
        if (res.success) {
          const { result } = res
          this.$set( this.model, 'disposalPersonId', result.disposalPersonId )
          this.$set( this.model, 'disposalPersonName', result.disposalPersonName )
          this.$set( this.model, 'infoId', result.infoId )
          this.$set( this.model, 'hitTime', result.hitTime )
          this.$set( this.model, 'intelligenceNumber', result.intelligenceNumber )
          this.$set( this.model, 'disposalInstructions', result.disposalInstructions )
        } else {
          this.$message.warn(res.message)
        }
      }).catch(e=>{
        that.$message.warn("操作失败！")
      })
    },
    handleOk() {
      const parameter = Object.assign({}, this.model)
      this.$refs.realForm.validate((valid)=> {
        if (valid) {
          informationDisposal(parameter)
            .then(res => {
              if (res.success) {
                this.$message.success(res.message)
                this.$emit('ok')
                this.handleCancel()
              } else {
                this.$message.warn(res.message)
              }
            })
            .catch(e => {
              this.$message.warn('请求失败！')
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleCancel() {
      this.visible = false
      this.model = {}
    }
  }
}
</script>
<style lang="less" scoped>
</style>
